$(function () {
	$("#loginForm").on("submit", function (event) {
		event.preventDefault();

		var nickname = $("#nickname").val();
		var password = $("#password").val();

		$.ajax({
			url: "http://localhost:8080/user/login",
			type: "post",
			dataType: "json",
			data: {
				"userNickname": nickname,
				"userPassword": password
			},
			success: function (rs) {
				if (rs.code === 2001) {
					// localStorage.setItem("token", rs.t);
					sessionStorage.setItem("token", rs.t);
					sessionStorage.setItem("nickname", nickname)
					alert('登录成功！')
					window.location.href = "index.html"
				} else {
					alert(rs.message);
				}
			},
			error: function (xhr, status, error) {
				alert("请求失败！");
				console.error("Error:", status, error);
			}
		})
	})
})